package com.rc.fragment;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;

import com.rc.activity.DashBoardScreen;
import com.rc.activity.LoadData;
import com.rc.activity.R;
import com.rc.activity.ReceiptBox;
import com.rc.activity.ReceiptBox.OnBackPressedListener;
import com.rc.activity.ReceiptBox.OnOpenSliding;
import com.rc.activity.ReportCreateNew;
import com.rc.activity.dao.tbl_Report;
import com.rc.activity.dao.tbl_ReportDao;
import com.rc.activity.dao.tbl_Trip;
import com.rc.activity.dao.tbl_TripItems;
import com.rc.activity.dao.tbl_TripItemsDao;
import com.rc.activity.provider.Contract;
import com.rc.adapter.DialogAdapter;
import com.rc.adapter.ReportListAdapter;
import com.rc.db.DatabaseSupport;
import com.rc.util.Util;
import com.telpoo.frame.ui.BaseFragment;
import com.telpoo.frame.utils.Utils;

@SuppressLint({ "DefaultLocale", "ValidFragment" })
public class ReportFragment extends BaseFragment implements OnClickListener,
		TextWatcher, OnBackPressedListener, OnOpenSliding {

	public TextView txtSearch;
	private MenuFragment menuFragment;
	private View v = null;
	private LinearLayout llAddNew;
	private RelativeLayout rlDateFilter, rlSelect, rlAllReport;
	private View loadMoreView;
	private Dialog dialog;
	private com.rc.custom.PullToRefreshListView lvReport;
	private ReportListAdapter adpReportList;
	private TextView txtSelect, txtTitle, txtAllReport, txtContent,
			txtEndDialog, txtStartDialog, txtStart, txtEnd, txtDash;
	private ImageView imgAllTrip;
	private LinearLayout llAction, llFuntion, llActionCancel, llSearch,
			llFuntionSearch, llContent, llSearchbtCancel, llApprove,
			llActionSubmit, llReject, llDelete;
	private ArrayList<tbl_Report> arrReportObj;
	private DatePicker dialog_datepicker;
	private String mIsStart = "";
	private int start = 0;
	private int end = 0;

	// variable String mKeyReport includes keywords for report type
	private String mReportType = "";

	// variable boolean isCheck check CheckBox in listview
	private boolean isCheck = true;

	public ReportFragment() {
		super();
	}

	public ReportFragment(String keyReport, int start, int end) {
		super();
		this.mReportType = keyReport;
		this.start = start;
		this.end = end;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		v = (ViewGroup) inflater.inflate(R.layout.reportlist, null);
		install();
		menuFragment = new MenuFragment();
		llActionSubmit.setOnClickListener(this);
		llReject.setOnClickListener(this);
		rlAllReport.setOnClickListener(this);
		rlDateFilter.setOnClickListener(this);
		llAddNew.setOnClickListener(this);
		rlSelect.setOnClickListener(this);
		llActionCancel.setOnClickListener(this);
		llSearch.setOnClickListener(this);
		llFuntionSearch.setOnClickListener(this);
		llDelete.setOnClickListener(this);
		llSearchbtCancel.setOnClickListener(this);
		llApprove.setOnClickListener(this);
		txtSearch.addTextChangedListener(this);
		// llArchive.setOnClickListener(this);

		return v;
	}

	@Override
	public void onResume() {
		super.onResume();
		arrReportObj = new ArrayList<tbl_Report>();
		arrReportObj = DatabaseSupport.getReportByReportType(start, end,
				mReportType, getActivity());

		adpReportList = new ReportListAdapter(getActivity(), arrReportObj,
				mReportType, start, end);
		if (arrReportObj.size() > 0 && lvReport.getFooterViewsCount() == 0) {
			// Install Load More View
			loadMoreView = ((LayoutInflater) getActivity().getSystemService(
					Context.LAYOUT_INFLATER_SERVICE)).inflate(
					R.layout.main_loadmore, null, false);
			lvReport.addFooterView(loadMoreView);
			loadMoreView.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					LoadData.callIntemt(getActivity(), 1);
				}
			});
		}
		lvReport.setAdapter(adpReportList);
		txtAllReport.setText(mReportType);
		txtContent.setText(mReportType);

		txtStart.setText(getString(R.string.all_date));
		if (mReportType.equals(getString(R.string.draft_reports))) {
			llDelete.setVisibility(View.VISIBLE);
		} else {
			llDelete.setVisibility(View.GONE);
		}
	}

	// Install View
	private void install() {
		((ReceiptBox) getActivity()).setTitle(getString(R.string.report_list));
		((ReceiptBox) getActivity()).setBackground(
				R.color.background_report_title, getResources());
		((ReceiptBox) getActivity()).setLogo(R.drawable.ic_top_travelexpense);
		((ReceiptBox) getActivity())
				.setOnBackPressedListener(new ReportFragment(mReportType,
						start, end));
		((ReceiptBox) getActivity()).setOnOpenSliding(new ReportFragment(
				mReportType, start, end));

		llAddNew = (LinearLayout) v.findViewById(R.id.llAddNew);
		rlDateFilter = (RelativeLayout) v.findViewById(R.id.rlDateFilter);
		rlSelect = (RelativeLayout) v.findViewById(R.id.rlSelect);
		lvReport = (com.rc.custom.PullToRefreshListView) v
				.findViewById(R.id.PullToRefresh);
		txtSelect = (TextView) v.findViewById(R.id.txtSelect);
		imgAllTrip = (ImageView) v.findViewById(R.id.imgAllTrip);
		llAction = (LinearLayout) v.findViewById(R.id.llAction);
		llFuntion = (LinearLayout) v.findViewById(R.id.llFuntion);
		llActionSubmit = (LinearLayout) v.findViewById(R.id.llActionSubmit);
		llActionCancel = (LinearLayout) v.findViewById(R.id.llActionCancel);
		llSearch = (LinearLayout) v.findViewById(R.id.llSearch);
		llApprove = (LinearLayout) v.findViewById(R.id.llApprove);
		llDelete = (LinearLayout) v.findViewById(R.id.llDelete);
		llReject = (LinearLayout) v.findViewById(R.id.llReject);
		llFuntionSearch = (LinearLayout) v.findViewById(R.id.llFuntionSearch);
		txtSearch = (TextView) v.findViewById(R.id.txtSearch);
		llSearchbtCancel = (LinearLayout) v.findViewById(R.id.llSearchbtCancel);
		txtAllReport = (TextView) v.findViewById(R.id.txtAllReport);
		rlAllReport = (RelativeLayout) v.findViewById(R.id.rlAllReport);
		txtContent = (TextView) v.findViewById(R.id.txtContent);
		txtStart = (TextView) v.findViewById(R.id.txtStart);
		txtEnd = (TextView) v.findViewById(R.id.txtEnd);
		txtDash = (TextView) v.findViewById(R.id.txtDash);
		// llArchive = (LinearLayout) v.findViewById(R.id.llArchive);
		reportBroadcast = new ReportUpdateBroadcast();
	}

	private boolean myReportReceiverIsRegistered = false;
	private ReportUpdateBroadcast reportBroadcast;

	private class ReportUpdateBroadcast extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			Log.e("push-update-report", "1");
			resetDateListView(context);
		}

	}

	@Override
	public void onPause() {
		super.onPause();
		if (myReportReceiverIsRegistered) {
			getActivity().unregisterReceiver(reportBroadcast);
			myReportReceiverIsRegistered = false;
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.llFuntionSearch:
			llSearch.setVisibility(View.VISIBLE);
			llFuntion.setVisibility(View.GONE);
			break;
		case R.id.llAddNew:
			ReportCreateNew.callIntent(getActivity(), mReportType);
			break;
		case R.id.rlDateFilter:
			createDialogDateFilter();
			break;
		case R.id.btDialogCancel:
			if (dialog != null) {
				if (dialog_datepicker.getVisibility() == View.GONE) {
					dialog.dismiss();
				} else {
					visibilityDateTimeDialog(false, "");
				}
			}
			break;
		case R.id.llActionCancel:
			displayFuntionBarBottom();
			break;
		case R.id.btOK:
			if (dialog != null) {
				if (dialog_datepicker.getVisibility() == View.GONE) {
					dialog.dismiss();
				} else {
					visibilityDateTimeDialog(false, "");
				}
			}
			break;
		case R.id.txtStarts:
			visibilityDateTimeDialog(true, "0");
			break;
		case R.id.txtEnds:
			visibilityDateTimeDialog(true, "1");
			break;
		case R.id.rlSelect:
			visiableSelect(!adpReportList.isShowCheck);
			break;
		case R.id.llSearchbtCancel:
			displayFuntionBarBottom();
			resetDateListView(getActivity());
			txtSearch.setText("");
			txtSelect.setText(getString(R.string.select));
			llSearch.setVisibility(View.GONE);
			llFuntion.setVisibility(View.VISIBLE);
			Utils.hideKeyboard(getActivity(), (EditText) txtSearch);
			break;
		case R.id.llActionSubmit:

			updateReport(getListContentValuesUpdate(
					getString(R.string.submitted_reports), false, false));
			break;
		case R.id.llApprove:
			updateReport(getListContentValuesUpdate(
					getString(R.string.approved_reports), false, false));
			break;
		case R.id.llReject:
			updateReport(getListContentValuesUpdate(
					getString(R.string.rejected_reports), false, false));
			break;
		case R.id.rlAllReport:
			createDialogFilterReport();
			break;
		// case R.id.llArchive:
		// UpdateReport(getListContentValuesUpdate("", true, false));
		case R.id.llDelete:
			createDialogInfor(
					getString(R.string.are_you_sure_you_want_to_delete), 0);
		default:
			break;
		}
	}

	/**
	 * show message information
	 */
	private void createDialogInfor(String info, final int action) {
		final Dialog dialog = new Dialog(getActivity());
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.dialog_message);
		LinearLayout llOk, llCancel;
		TextView txtTitle = (TextView) dialog.findViewById(R.id.txtTitle);
		txtTitle.setText(getString(R.string.messages));
		TextView txtContent = (TextView) dialog.findViewById(R.id.txtContent);
		txtContent.setText(info);
		llOk = (LinearLayout) dialog.findViewById(R.id.llOk);
		llCancel = (LinearLayout) dialog.findViewById(R.id.llCancel);
		llCancel.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Util.HidenKeyBoard(getActivity());
				dialog.dismiss();
			}
		});
		llOk.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				dialog.dismiss();
				switch (action) {
				case 0:
					updateReport(getListContentValuesUpdate("", false, true));
					break;

				default:
					break;
				}
			}
		});
		dialog.show();
	}

	private void resetDateListView(Context ct) {
		arrReportObj = new ArrayList<tbl_Report>();
		arrReportObj = DatabaseSupport.getReportByReportType(start, end,
				mReportType, ct);
		if (arrReportObj == null) {
			return;
		}
		if (mReportType == null) {
			return;
		}
		adpReportList.notiB(arrReportObj, mReportType, start, end);
	}

	private ArrayList<ContentValues> getListContentValuesUpdate(
			String mReportType, boolean isArchive, boolean isDelete) {
		ArrayList<ContentValues> arrValues = new ArrayList<ContentValues>();
		for (tbl_Report objReport : arrReportObj) {
			if (objReport.getReportType().equals(
					getString(R.string.rejected_reports))) {
				ArrayList<tbl_Trip> arrTrip = new ArrayList<tbl_Trip>();
				arrTrip = DatabaseSupport.getTripbyReportID(
						objReport.getReportID() + "", getActivity());
				for (tbl_Trip objTrip : arrTrip) {
					ArrayList<tbl_TripItems> arrTripItem = new ArrayList<tbl_TripItems>();
					arrTripItem = DatabaseSupport.getTripItemsByTripID(
							objTrip.getTripID(), getActivity());
					for (tbl_TripItems objTripItem : arrTripItem) {
						objTripItem.setApproved(objTripItem.getClaimed());
						objTripItem.setIsUpdate("1");
						getActivity().getContentResolver().update(
								Contract.CONTENT_URI_TRIP_ITEM,
								objTripItem.getContentValues(),
								tbl_TripItemsDao.Properties.TripItemID + " = "
										+ objTripItem.getTripItemID(), null);
					}
				}
			}
			if (objReport.isIsCheck()) {
				if (isArchive) {
					objReport.setIsUpdate("1");
					objReport.setIsArchived(1);
				} else if (isDelete) {
					objReport.setIsDelete("1");
				} else
					objReport.setReportType(mReportType);
				arrValues.add(objReport.getContentValues());
			}
		}
		return arrValues;
	}

	/**
	 * update report
	 */
	private void updateReport(ArrayList<ContentValues> arrValues) {
		if (arrValues == null) {
			return;
		}
		int row = 0;
		for (ContentValues value : arrValues) {
			row = row
					+ getActivity().getContentResolver().update(
							Contract.CONTENT_URI_REPORT,
							value,
							tbl_ReportDao.Properties.ReportID.columnName
									+ " = '"
									+ tbl_Report.setContentValues(value)
											.getReportID() + "'", null);
		}

		if (row > 0) {
			resetDateListView(getActivity());
		}
		menuFragment.resetMenuList(getResources(), getActivity());
	}

	/**
	 * This function shows and control date picker If isStart = true & isEnable
	 * = false --> disable Start If isStart = true & isEnable = true --> enable
	 * Start If isStart = false & isEnable = false --> disable End If isStart =
	 * false & isEnable = true --> enable End If isStart = "" or null --> return
	 * void;
	 */

	private void visibilityDateTimeDialog(boolean isEnable, String isStart) {
		if (isEnable) {
			dialog_datepicker.setVisibility(View.VISIBLE);
			llContent.setVisibility(View.GONE);
			txtTitle.setText(getString(R.string.choose_calendar));
			mIsStart = isStart;
		} else {
			String date_choose = Util
					.getDateByDateTimePicker(dialog_datepicker);
			if ("0".equals(mIsStart)) {
				txtStartDialog.setText(date_choose);
			} else {
				txtEndDialog.setText(date_choose);
			}
			mIsStart = "";
			dialog_datepicker.setVisibility(View.GONE);
			llContent.setVisibility(View.VISIBLE);
			txtTitle.setText(getString(R.string.date_filter));
		}
	}

	/**
	 * filter dialog by Report
	 */
	private void createDialogFilterReport() {
		dialog = new Dialog(getActivity());
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.dialog_receipt_choosetime);
		final ListView lvDialog = (ListView) dialog.findViewById(R.id.lvDialog);
		((TextView) dialog.findViewById(R.id.txtTitle))
				.setText(getString(R.string.filter_reports_by_type));
		;
		DialogAdapter adpDialog = new DialogAdapter(getActivity(),
				DatabaseSupport
						.getArrReportTypes(getResources(), getActivity()),
				txtAllReport.getText().toString());
		lvDialog.setAdapter(adpDialog);
		lvDialog.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				dialog.dismiss();
				mReportType = ((TextView) lvDialog.getChildAt(position)
						.findViewById(R.id.txtTextDialog)).getText().toString();
				txtAllReport.setText(mReportType);
				txtContent.setText(mReportType);
				resetDateListView(getActivity());
				actionShowBarBottom(mReportType);
			}
		});
		dialog.show();
	}

	/**
	 * filter dialog by time
	 */
	@SuppressLint("NewApi")
	private void createDialogDateFilter() {
		dialog = new Dialog(getActivity());
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.dialog_trip_datefilter);

		Button btCancel, btOK;
		llContent = (LinearLayout) dialog.findViewById(R.id.llContent);
		btCancel = (Button) dialog.findViewById(R.id.btDialogCancel);
		btOK = (Button) dialog.findViewById(R.id.btOK);
		txtEndDialog = (TextView) dialog.findViewById(R.id.txtEnds);
		txtStartDialog = (TextView) dialog.findViewById(R.id.txtStarts);
		txtTitle = (TextView) dialog.findViewById(R.id.txtTitle);

		final Switch mSwitch = (Switch) dialog.findViewById(R.id.swAllDate);
		mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				// TODO Auto-generated method stub
				if (!isChecked) {
					txtStartDialog.setEnabled(false);
					txtEndDialog.setEnabled(false);
				} else {
					txtStartDialog.setEnabled(true);
					txtEndDialog.setEnabled(true);
				}
			}
		});
		dialog_datepicker = (DatePicker) dialog
				.findViewById(R.id.dialog_datepicker);
		dialog.show();

		btCancel.setOnClickListener(this);
		btOK.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (dialog != null) {

					if (dialog_datepicker.getVisibility() == View.GONE) {
						dialog.dismiss();
						if (!mSwitch.isChecked()) {
							start = 0;
							end = 0;
							txtStart.setText(getString(R.string.all_date));
							txtDash.setVisibility(View.GONE);
							txtEnd.setText("");
							resetDateListView(getActivity());
						} else {
							String startString = txtStartDialog.getText()
									.toString();
							startString = startString.replace("/", "-");
							start = Util.parseDateForInt(startString);
							String endString = txtEndDialog.getText()
									.toString();
							endString = endString.replace("/", "-");
							end = Util.parseDateForInt(endString);
							resetDateListView(getActivity());
							txtStart.setText(txtStartDialog.getText()
									.toString());
							txtEnd.setText(txtEndDialog.getText().toString());

							txtDash.setVisibility(View.VISIBLE);
						}
					} else {
						visibilityDateTimeDialog(false, "");
					}

				}
			}
		});
		;
		txtEndDialog.setOnClickListener(this);
		txtStartDialog.setOnClickListener(this);
		txtEndDialog.setText(Util.getDefaultInfor());
		txtStartDialog.setText(Util.getDefaultInfor());
	}

	/**
	 * Display/Hidden select box
	 */
	private void visiableSelect(boolean mIsSelect) {
		if (mIsSelect) {
			llAction.setVisibility(View.VISIBLE);
			llFuntion.setVisibility(View.GONE);
			adpReportList.isShowCheck = true;
			isCheck = false;
			imgAllTrip.setImageResource(R.drawable.ic_selectitem);
			txtSelect.setText(getString(R.string.select_all));
			adpReportList.notifyDataSetChanged();

		} else {
			setImgSelect(isCheck);

		}
		actionShowBarBottom(txtAllReport.getText().toString());
	}

	/**
	 * Show barbottom depends on report type
	 */
	private void actionShowBarBottom(String mKeyShowBarBottom) {
		actionBarBottomIsGone();
		if (getString(R.string.all_reports).equals(mKeyShowBarBottom)) {
			llDelete.setVisibility(View.VISIBLE);
			// llArchive.setVisibility(View.VISIBLE);
		} else if (getString(R.string.approved_reports).equals(
				mKeyShowBarBottom)) {
			// llArchive.setVisibility(View.VISIBLE);
		} else if (getString(R.string.draft_reports).equals(mKeyShowBarBottom)) {
			llActionSubmit.setVisibility(View.VISIBLE);
			llDelete.setVisibility(View.VISIBLE);
		} else if (getString(R.string.pending_reports)
				.equals(mKeyShowBarBottom)) {
			llApprove.setVisibility(View.VISIBLE);
			llReject.setVisibility(View.VISIBLE);
		} else if (getString(R.string.rejected_reports).equals(
				mKeyShowBarBottom)) {
			llActionSubmit.setVisibility(View.VISIBLE);
			llDelete.setVisibility(View.VISIBLE);
		} else if (getString(R.string.submitted_reports).equals(
				mKeyShowBarBottom)) {
		}
	}

	/**
	 * Hidden all actions in bar bottom
	 */
	private void actionBarBottomIsGone() {
		llDelete.setVisibility(View.GONE);
		llActionSubmit.setVisibility(View.GONE);
		llApprove.setVisibility(View.GONE);
		llReject.setVisibility(View.GONE);
	}

	/**
	 * Display checkbox in listview if val = false --> off, val = true -->
	 */

	private void toggleCheck(Boolean val) {
		for (int i = 0; i < lvReport.getChildCount(); i++) {
			CheckBox cbMulti = null;
			cbMulti = (CheckBox) lvReport.getChildAt(i).findViewById(
					R.id.cbMulti);
			if (cbMulti != null)
				cbMulti.setChecked(val);
		}
	}

	/**
	 * setImage cho ImgAllReport và setText cho txtSelect
	 */
	private void setImgSelect(boolean isSelect) {
		toggleCheck(!isSelect);
		if (isSelect) {
			imgAllTrip.setImageResource(R.drawable.ic_selectitem);
			txtSelect.setText(getString(R.string.select_all));
			isCheck = false;
			for (tbl_Report objReport : arrReportObj) {
				objReport.setIsCheck(false);
			}
		} else {
			for (tbl_Report objReport : arrReportObj) {
				objReport.setIsCheck(true);
			}
			imgAllTrip.setImageResource(R.drawable.ic_selectall);
			txtSelect.setText(getString(R.string.unselect_all));
			isCheck = true;
		}

	}

	/**
	 * Display functions in bar bottom
	 */
	private void displayFuntionBarBottom() {
		txtSelect.setText(getString(R.string.select));
		imgAllTrip.setImageResource(R.drawable.ic_selectitem);
		llAction.setVisibility(View.GONE);
		llFuntion.setVisibility(View.VISIBLE);
		adpReportList.isShowCheck = false;
		adpReportList.notifyDataSetChanged();
		toggleCheck(adpReportList.isShowCheck);
	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		if (txtSearch.getText().toString().length() > 0) {
			adpReportList
					.notiB(searchListView(arrReportObj, txtSearch.getText()
							.toString()), mReportType, this.start, end);
		} else {
			resetDateListView(getActivity());
		}
	}

	@Override
	public void afterTextChanged(Editable s) {
		// TODO Auto-generated method stub

	}

	/**
	 * Search trong listview
	 * 
	 */

	public ArrayList<tbl_Report> searchListView(
			ArrayList<tbl_Report> arrReportBox, String contentSearch) {
		if (arrReportBox == null) {
			return null;
		}
		ArrayList<tbl_Report> _arrReportList = new ArrayList<tbl_Report>();

		for (int i = 0; i < arrReportBox.size(); i++) {
			if (arrReportBox.get(i).getTitle() != null) {
				if (arrReportBox.get(i).getTitle().toUpperCase()
						.contains(contentSearch.toUpperCase())
						|| arrReportBox.get(i).getAmount().toUpperCase()
								.contains(contentSearch.toUpperCase())) {
					_arrReportList.add(arrReportBox.get(i));
				}
			}

		}
		return _arrReportList;
	}

	@Override
	public void doBack(Activity at) {
		DashBoardScreen.callIntent(at);
	}

	@Override
	public void doOpen(Activity at) {
		Util.HidenKeyBoard(at);
	}

}
